from flask import Blueprint,Flask,jsonify
from flask import request,session,Response
import json
bp = Blueprint("room", __name__)
 
from src.database.getdb import database 
db=database().create_db()
from src.database.redis import Db_Redis
from src.model.room import Room
from src.router.login import checklogin
from functools import wraps
from jwt import JWT
from jwt import jwk
from const import secret_key

def verify_token(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            decoded_data = JWT().decode(request.headers.get('token'), jwk.OctetJWK(secret_key.encode()), algorithms='HS256')
            current_user = decoded_data['user']
            kwargs['current_user'] = current_user
            return func(*args, **kwargs)
        except :
            return jsonify({'error': 'Invalid or expired token'}), 401
    return wrapper


@checklogin
@bp.route('/create_room',methods=['GET'])
@verify_token
def create_room(current_user):
    data={'code':0,'mess':'error'}  
    if request.method == "GET":
        data = Room().create_room()
        
    return json.dumps(data)






